home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / mac / bonus / peter_le / finger_1 / tokens / idleword.c < prev    next >
C/C++ Source or Header  |  1992-01-21  |  4KB  |  82 lines

  1. /* Fingerd IDLEINWORDS PROC                                         */
  2. /* written by Stuart Cheshire <cheshire@cs.stanford.edu>            */
  3. /*                                                                  */
  4. /* To compile using Think C:                                        */
  5. /* Create a new project and add only this file to it (Source menu)  */
  6. /* Set Project Type (Project menu) to:                              */
  7. /*     Code Resource                                                */
  8. /*     File Type:   rsrc                                            */
  9. /*     Creator:     RSED                                            */
  10. /*     DO NOT check Multi-Segment                                   */
  11. /*     Name:        IDLEINWORDS                                     */
  12. /*     Type:        PROC                                            */
  13. /*     ID:          139                                             */
  14. /*     DO NOT check Custom Header                                   */
  15. /*     Attrs:       20 (Purgeable)                                  */
  16. /*                                                                  */
  17. /* Build Code Resource (Project menu) and save the file as          */
  18. /* ╥IDLEINWORDS.rsrc╙. You can now double-click the file produced   */
  19. /* to open it in ResEdit, from where you can copy and paste the     */
  20. /* PROC resource into your ╥Finger Preferences╙ file. To make your  */
  21. /* own token, change the name of the PROC resource and change the   */
  22. /* ID to be above 1000 to ensure that it does not clash with the    */
  23. /* ID of any pre-defined token.                                     */
  24. /*                                                                  */
  25. /* Note that ╥main╙ MUST be declared ╥pascal void╙ in order to work.*/
  26.  
  27. typedef struct
  28.     {
  29.     StringPtr fingeredname;    // In  - name the caller specified
  30.     StringPtr param;        // In  - parameter following special token
  31.     StringPtr returnvalue;    // Out - return string, to be appended to finger output.  Don't change ptr!
  32.     Handle    fingeroutput;    // I/O - Handle to finger output as it╒s built.
  33.     long      hlength;        // I/O - handle length. 
  34.     long      offset;        // I/O - offset from start of handle that finger output is up to
  35.     long      idle;            // In  - Idle time in seconds
  36.     long      remoteIP;        // In  - IP address of fingerer
  37.     Boolean   expandtokens;    // Out - Expand <cr>s and %tokens inserted into the fingeroutput handle
  38.     } parameterRecord;
  39.  
  40. #define MINUTE 60
  41. #define HOUR (MINUTE*60)
  42. #define DAY  (HOUR*24L)
  43.  
  44. static void Pstr(StringPtr dest, StringPtr src)
  45.     {
  46.     unsigned char *ptr = dest + 1 + *dest;
  47.     unsigned char len  = *src++;
  48.     *dest += len;
  49.     while (len--) *ptr++ = *src++;
  50.     }
  51.  
  52. static void Pnum(StringPtr dest, short number)
  53.     {
  54.     if (number > 9) Pnum(dest, number / 10);
  55.     *(dest + ++(*dest)) = number % 10 + '0';
  56.     }
  57.  
  58. static void Ppair(StringPtr dest, short n1, StringPtr s1, short n2, StringPtr s2)
  59.     {
  60.     if (n1)
  61.         {
  62.         Pnum(dest, n1);
  63.         Pstr(dest, s1);
  64.         if (n1>1) Pstr(dest, "\ps");
  65.         Pstr(dest, "\p ");
  66.         }
  67.     Pnum(dest, n2);
  68.     Pstr(dest, s2);
  69.     if (n2>1) Pstr(dest, "\ps");
  70.     }
  71.  
  72. pascal void main(parameterRecord *p)
  73.     {
  74.     long i = p->idle;
  75.     *p->returnvalue = 0;    /* set initial length of result string to zero */
  76.     if      (i == 0)   Pstr (p->returnvalue, "\pNo");
  77.     else if (i < HOUR) Ppair(p->returnvalue, i/MINUTE, "\p minute", (i%MINUTE),      "\p second");
  78.     else if (i < DAY ) Ppair(p->returnvalue, i/HOUR,   "\p hour",   (i%HOUR)/MINUTE, "\p minute");
  79.     else               Ppair(p->returnvalue, i/DAY,    "\p day",    (i%DAY) /HOUR,   "\p hour"  );
  80.     }
  81.  
  82.